<template>
    <div>
        <el-form :model="selectFormData" ref="selectFormData" label-width="100px" class="selectForm" >
            <el-row>
                <el-col :span="6">
                    <el-form-item label="专家姓名" prop="proName">
                        <el-input v-model="selectFormData.proName" placeholder="专家姓名"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="专家身份证" prop="proId">
                        <el-input v-model="selectFormData.proId" placeholder="专家身份证"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="4">
                    <el-form-item label="最低年龄" prop="proLowAge" @change="handleLowAgeChange">
                        <el-select v-model="selectFormData.proLowAge" placeholder="最低年龄">
                            <el-option v-for="item in allAges" :key='item' :label="item" :value="item"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                
                <el-col :span="4">
                    <el-form-item label="最高年龄" prop="proHighAge" >
                        <el-select v-model="selectFormData.proHighAge" placeholder="最高年龄">
                            <el-option v-for="item in filteredMaxAges" :key='item' :label="item" :value="item"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="4">
                    <el-form-item label="专家性别" prop="proGender">
                        <el-select v-model="selectFormData.proGender" placeholder="请选择性别">
                            <el-option label="女" value="0"></el-option>
                            <el-option label="男" value="1"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="6">
                    <el-form-item label="专家邮箱" prop="proEmail">
                        <el-input v-model="selectFormData.proEmail"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="专家电话" prop="proPhone">
                        <el-input v-model="selectFormData.proPhone"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="专家权限" prop="proAuth">
                        <el-select v-model="selectFormData.proAuth" placeholder="请选择权限">
                            <el-option v-for="auth in auths.slice(1,4)" :key="auth.authId" :label="auth.authDesc" :value="auth.authId"></el-option>  
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="专家类别" prop="proClass">
                        <el-select v-model="selectFormData.proClass" placeholder="请选择类别">
                            <el-option v-for="cls in classes" :key="cls.classId" :label="cls.className" :value="cls.classId"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12" style="text-align: left;">专家表</el-col>
                <el-col :span="12" style="text-align: right;">
                    <el-button type="primary" @click="findByData" icon="el-icon-search">查询</el-button>
                    <el-button type="warning" @click="resetForm" icon="el-icon-refresh-right" plain>重置</el-button>
                    <el-button type="primary" @click="dialogAddFormVisible = true" icon="el-icon-circle-plus-outline">新增</el-button>
                </el-col>
            </el-row>
        </el-form>

        <el-dialog title="新增信息" :visible.sync="dialogAddFormVisible" id="AddDialog" :close-on-click-modal="false"
            @close="resetForm('addformdata')">
            <el-form :model="addformData" :rules="profRules" class="parentBox" ref="addformData">
                <el-form-item label="专家身份证" :label-width="formLabelWidth" prop="proId">
                    <el-input v-model="addformData.proId" @blur="getName(addformData.proId)">
                    </el-input>
                </el-form-item>
                <el-form-item label="专家姓名" :label-width="formLabelWidth" prop="proName">
                    <el-input v-model="addformData.proName"></el-input>
                </el-form-item>
                <el-form-item label="默认密码" :label-width="formLabelWidth" prop="proName">
                    <el-input v-model="addformData.proPassword"></el-input>
                </el-form-item>
                <el-form-item label="性别" prop="proGender" :label-width="formLabelWidth">
                    <el-radio-group v-model="addformData.proGender" disabled="true">
                        <el-radio :label="0">女</el-radio>
                        <el-radio :label="1">男</el-radio>
                        
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="年龄" prop="proAge" :label-width="formLabelWidth">
                    <el-input v-model="addformData.proAge" placeholder="年龄" disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="邮件" prop="proEmail" :label-width="formLabelWidth">
                    <el-input v-model="addformData.proEmail" placeholder="邮件"></el-input>
                </el-form-item>
                <el-form-item label="电话" prop="proPhone" :label-width="formLabelWidth">
                    <el-input v-model="addformData.proPhone" placeholder="电话"></el-input>
                </el-form-item>
                <el-form-item label="专家权限" prop="proAuth" :label-width="formLabelWidth">
                    <el-select v-model="addformData.proAuth" placeholder="权限">
                        <el-option v-for="auth in auths.slice(1,4)" :key="auth.authId" :label="auth.authDesc" :value="auth.authId"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="专家类别" prop="proClass" :label-width="formLabelWidth">
                    <el-select v-model="addformData.proClass" placeholder="类别">
                        <el-option v-for="cls in classes" :key="cls.classId" :label="cls.className" :value="cls.classId"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="专家生日" prop="proBirth" :label-width="formLabelWidth">
                    <el-date-picker v-model="addformData.proBirth" 
                    type="date" 
                    disabled="true"
                    placeholder="选择日期"
                     format="yyyy 年 MM 月 dd 日"
                    value-format="yyyy-MM-dd">
                    </el-date-picker>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancel">取 消</el-button>
                <el-button type="primary" @click="submitAddForm">确 定</el-button>
            </div>
        </el-dialog>
        <el-dialog title="编辑信息" :visible.sync="dialogEditFormVisible" id="EditDialog" :close-on-click-modal="false"
            @close="resetForm('Editformdata')">
            <el-form :model="editformData"  class="parentBox" ref="editformData" label-position="left">
                <el-form-item label="专家身份证" :label-width="formLabelWidth" prop="proId">
                    <el-input v-model="editformData.proId" disabled="true">
                    </el-input>
                    <el-button type="info" size="small" disabled>不可修改</el-button>
                </el-form-item>
                <el-form-item label="专家姓名" :label-width="formLabelWidth" prop="proName">
                    <el-input v-model="editformData.proName" :disabled="namedis"></el-input>
                    <el-button type="primary" @click="nameEdit">修改</el-button>
                </el-form-item>
                <el-form-item label="密码" :label-width="formLabelWidth" prop="proName">
                    <el-input v-model="editformData.proPassword" disabled="true"></el-input>
                    <el-button @click="resetPassword">重置</el-button>
                </el-form-item>
                <el-form-item label="性别" prop="proGender" :label-width="formLabelWidth">
                    <el-radio-group v-model="editformData.proGender" disabled="true">
                        <el-radio :label="0">女</el-radio>
                        <el-radio :label="1">男</el-radio>
                    </el-radio-group>
                    <el-button type="info" size="small" disabled>不可修改</el-button>
                </el-form-item>
                <el-form-item label="年龄" prop="proAge" :label-width="formLabelWidth">
                    <el-input v-model="editformData.proAge" placeholder="年龄" disabled="true"></el-input>
                    <el-button type="info" size="small" disabled>不可修改</el-button>
                </el-form-item>
                <el-form-item label="邮件" prop="proEmail" :label-width="formLabelWidth">
                    <el-input v-model="editformData.proEmail" placeholder="邮件" :disabled="emaildis"></el-input>
                    <el-button type="primary" @click="emailEdit">修改</el-button>
                </el-form-item>
                <el-form-item label="电话" prop="proPhone" :label-width="formLabelWidth">
                    <el-input v-model="editformData.proPhone" placeholder="电话" :disabled="phonedis"></el-input>
                    <el-button type="primary" @click="phoneEdit">修改</el-button>
                </el-form-item>
                <el-form-item label="专家权限" prop="proAuth" :label-width="formLabelWidth" >
                    <el-select v-model="editformData.proAuth" placeholder="权限" :disabled="authdis" style="width: 50%;">
                        <el-option v-for="auth in auths.slice(1,4)" :key="auth.authId" :label="auth.authDesc"
                            :value="auth.authId"></el-option>
                    </el-select>
                    <el-button type="primary" @click="authEdit">修改</el-button>
                </el-form-item>
                <el-form-item label="专家类别" prop="proClass" :label-width="formLabelWidth" >
                    <el-select v-model="editformData.proClass" placeholder="类别" :disabled="classdis" style="width: 50%;">
                        <el-option v-for="cls in classes" :key="cls.classId" :label="cls.className"
                            :value="cls.classId"></el-option>
                    </el-select>
                    <el-button type="primary" @click="classEdit">修改</el-button>
                </el-form-item>
                <el-form-item label="专家生日" prop="proBirth" :label-width="formLabelWidth">
                    <el-date-picker v-model="editformData.proBirth" type="date" disabled="true" placeholder="选择日期"
                        format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd">
                    </el-date-picker>
                    <el-button type="info" size="small" disabled>不可修改</el-button>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="Editcancel">取 消</el-button>
                <el-button type="primary" @click="submitEditForm">确 定</el-button>
            </div>
        </el-dialog>
        <!-- 表格 -->
        <el-table :data="tableData" :height="tableHeight" style="width: 100%" border>
            <el-table-column prop="proIndex" label="序号"></el-table-column>
            <el-table-column label="姓名" width="130">
                <template slot-scope="scope">
                    <el-popover trigger="hover" placement="top">
                        <p>姓名: {{ scope.row.proName }}</p>
                        <p>邮箱: {{ scope.row.proEmail }}</p>
                        <p>密码: {{ scope.row.proPassword }}</p>
                        <p>电话: {{ scope.row.proPhone }}</p>
                        <div slot="reference" class="name-wrapper">
                            <el-tag >{{ scope.row.proName }}</el-tag>
                        </div>
                    </el-popover>
                </template>
            </el-table-column>
            <el-table-column prop="proId" label="身份证"></el-table-column>
            <el-table-column prop="proAge" label="年龄"></el-table-column>
            <el-table-column prop="proAuth" label="专家权限">
                <template slot-scope="scope" v-if="scope && auths[scope.row.proAuth-1]">
                    {{  auths[scope.row.proAuth-1].authDesc }}
                </template>
            </el-table-column>
            <el-table-column prop="proClass" label="专家类别" >
                <template slot-scope="scope" v-if="scope && classes[scope.row.proClass-1]">
                    {{ classes[scope.row.proClass-1].className }}
                </template>
            </el-table-column>
            <el-table-column prop="proBirth" label="专家生日"></el-table-column>
            <el-table-column prop="proCreatetime" label="创建时间" :formatter="formatterTime"></el-table-column>
            <el-table-column prop="proUpdatetime" label="更新时间" :formatter="formatterTime"></el-table-column>
            <!-- 其他列... -->
        
            <el-table-column label="操作" width="180">
                <template slot-scope="scope">
                    <el-button size="small" @click="editRow(scope.$index, scope.row)">编辑</el-button>
                    <el-button size="small" type="danger" @click="deleteRow(scope.$index, scope.row.proIndex)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="selectFormData.currentPage"
            :page-sizes="[10, 20, 30, 40]" :page-size="selectFormData.pageSize" layout="total, sizes, prev, pager, next, jumper"
            :total="totalCount">
        </el-pagination>
    </div>
</template>

<script>
    import moment from 'moment';
    export default {
        
        name: "professormanage",
        data() {
            //身份证号格式校验
            var isCardId = (rule, value, callback) => {
                if (!value) {
                    return new Error("请输入身份证号)");
                } else {
                    const reg =
                        /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[0-2])(([0-2][1-9])|10|20|30|31)\d{3}(\d|X|x)$/;
                    const card = reg.test(value);
                    if (!card) {
                        callback(new Error("身份证号格式有误！"));
                    } else {
                        callback();
                    }
                }
            };
            //手机号格式校验
            var validatorPhone = function (rule, value, callback) {
                if (value === '') {
                    callback(new Error('手机号不能为空'))
                } else if (!/^1\d{10}$/.test(value)) {
                    callback(new Error('手机号格式错误'))
                } else {
                    callback()
                }
            };
            var validEmail = (rule, value, callback) => {
                const mailReg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/
                if (!value) {
                    return callback(new Error('邮箱不能为空'))
                }
                setTimeout(() => {
                    if (mailReg.test(value)) {
                        callback()
                    } else {
                        callback(new Error('请输入正确的邮箱格式'))
                    }
                }, 100)
            };
            return {
                disabled:true,
                namedis:true,
                emaildis:true,
                phonedis:true,
                authdis:true,
                classdis:true,
                password_reset:false,
                dialogEditFormVisible:false,
                formLabelWidth: '120px',
                totalCount: 0, // 总记录数
                selectFormData: {
                    currentPage: 1, // 当前页码
                    pageSize: 10, // 每页显示数量
                    proId:'',
                    proName:'',
                    proLowAge:'',
                    proHighAge: '',
                    proGender:'',
                    proEmail:'',
                    proPhone:'',
                    proAuth:'',
                    proClass:''
                    
                },
                classes:[{
                    classId:'',
                    className:''
                }
                ],
                auths:[{
                    authId:'',
                    authName: "",
                    authDesc: ""
                }
                ],
                
                allAges: [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 
                        39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
                        50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 
                        61, 62, 63, 64, 65, 66, 67, 68, 69, 70],
                filteredMaxAges:[],
                dialogAddFormVisible:false,
                editformData:{
                    proIndex: '',
                    proId: '',
                    proName: '',
                    proAge: '',
                    proGender: '',
                    proPassword: '',
                    proEmail: '',
                    proPhone: '',
                    proAuth: '',
                    proClass: '',
                    proBirth: '',
                    proCreatetime: '',
                    proUpdatetime: ''
                },
                rowData: {
                    proIndex: '',
                    proId: '',
                    proName: '',
                    proAge: '',
                    proGender: '',
                    proPassword: '',
                    proEmail: '',
                    proPhone: '',
                    proAuth: '',
                    proClass: '',
                    proBirth: '',
                    proCreatetime: '',
                    proUpdatetime: ''
                },
                addformData: {
                    proIndex:'',
                    proId: '',
                    proName: '',
                    proAge: '',
                    proGender: '',
                    proPassword:'',
                    proEmail: '',
                    proPhone: '',
                    proAuth: '',
                    proClass: '',
                    proBirth: '',
                    proCreatetime:'',
                    proUpdatetime:''
                }, 
                tableData:[],
                profRules:{
                    proName:[
                        { required: true, message: "请输入姓名", trigger: "blur" },
                        { min:2,max:10,message:'长度在2-10个字符', trigger: "blur"  }
                    ],
                    proId:[
                        { required: true, trigger: "blur" },
                        { validator: isCardId, trigger: 'blur' }
                    ],
                    proGender:[
                    { required: true, message: "请输入年龄", trigger: "blur" }
                    ],
                    proAge:[{
                        required: true, message: "请输入年龄", trigger: "blur" 
                    }
                    ],
                    proEmail:[
                        { required: true, trigger: "blur" },
                        { validator: validEmail, trigger: 'blur' } 
                    ],
                    proPhone:[
                        {required: true,trigger: "blur"},
                        { validator: validatorPhone, trigger: 'blur' }
                    ],
                    proAuth:[
                        { required: true, message: "请选择权限", trigger: "blur" }
                    ],
                    proClass:[
                        { required: true, message: "请选择类别", trigger: "blur" }
                    ],
                    proBirth:[
                        { required: true, message: "", trigger: "blur" }
                    ]

                },
                tableHeight: window.innerHeight - 300,
            };
        },
        watch: {
                    'selectFormData.proLowAge'(newVal) {
                        this.filteredMaxAges = this.allAges.filter(age => age > newVal);
                    }
                },
        methods: {
            formatterTime(row, column, cellValue, index) {
                return moment.utc(cellValue).local().format('YYYY-MM-DD HH:mm:ss');
            },
            getHeight() {
                console.log("tableHeight:" + this.tableHeight);
                this.tableHeight = window.innerHeight - 300;
            },
            cancel() {
                this.$refs.addformData.resetFields();
                this.dialogAddFormVisible = false
            },
            Editcancel(){
                this.dialogEditFormVisible = false;
            },
            nameEdit(){
                this.namedis=!this.namedis;
                if (this.namedis == true) {
                    this.editformData.proName = this.rowData.proName;
                }
            },
            emailEdit(){
                this.emaildis = !this.emaildis;
                if (this.emaildis == true) {
                    this.editformData.proEmail = this.rowData.proEmail;
                }
            },
            phoneEdit(){
                this.phonedis = !this.phonedis
                if (this.phonedis == true) {
                    this.editformData.proPhone = this.rowData.proPhone;
                }
            },
            authEdit(){
                this.authdis = !this.authdis
                if(this.authdis==true){
                    this.editformData.proAuth = this.rowData.proAuth;
                }
            },
            classEdit(){
                this.classdis = !this.classdis;
                if (this.classdis == true) {
                    this.editformData.proClass = this.rowData.proClass;
                }
            },
            submitEditForm(){
               var postData={
                    proIndex:this.editformData.proIndex,
                    proId: null,
                    proName: null,
                    proAge: null,
                    proGender: null,
                    proPassword: null,
                    proEmail: null,
                    proPhone: null,
                    proAuth: null,
                    proClass: null,
                    proBirth: null,
                    proCreatetime: '',
                    proUpdatetime: ''
                };
                console.log(this.namedis, this.password_reset, this.emaildis, this.phonedis, this.classdis, this.authdis);
                
                if(this.namedis===false && this.editformData.proName !=this.rowData.proName){
                    postData.proName=this.editformData.proName;
                }
                if (this.password_reset === true) {
                    postData.proPassword = this.editformData.proPassword;
                }
                if(this.emaildis === false && this.editformData.proEmail != this.rowData.proEmail){
                    postData.proEmail = this.editformData.proEmail;
                }
                if (this.phonedis === false && this.editformData.proPhone != this.rowData.proPhone) {
                    postData.proPhone = this.editformData.proPhone;
                }
                if (this.classdis === false && this.editformData.proClass != this.rowData.proClass) {
                    postData.proClass = this.editformData.proClass;
                }
                if (this.authdis === false && this.editformData.proAuth != this.rowData.proAuth) {
                    postData.proAuth = this.editformData.proAuth;
                }
                if(!(this.namedis === false && this.editformData.proName != this.rowData.proName)
                && this.password_reset === false 
                && !(this.emaildis === false && this.editformData.proEmail != this.rowData.proEmail)
                && !(this.phonedis === false && this.editformData.proPhone != this.rowData.proPhone)
                && !(this.classdis === false && this.editformData.proClass != this.rowData.proClass)
                && !(this.authdis === false && this.editformData.proAuth != this.rowData.proAuth) ){
                    
                    this.dialogEditFormVisible = false;
                    alert("无修改操作");
                }else{
                    var dangerPostData = {
                        'userId': this.$store.state.userdata.userId,
                        'userName': this.$store.state.userdata.userName,
                        'userEnterId': this.$store.state.userdata.userId,
                        postData: postData
                    }
                    this.$axios({
                        method: 'post',
                        url: "http://localhost:8080/professors/danger_edit",
                        data: JSON.stringify(dangerPostData),
                        headers: { 'Content-Type': 'application/json' },
                    }).then(res=>{
                        if(res.data.code==1){
                            alert("修改成功");
                            this.dialogEditFormVisible = false;
                            this.fetchData();
                        }else{
                            alert(res.data.msg);
                            this.dialogEditFormVisible = false;
                        }
                    })
                }
                

            },
            submitAddForm(){
                this.$refs.addformData.validate((valid) => {
                    if (valid) {
                        this.$prompt('此操作将被记录，请输入身份证号', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            inputPattern: /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[0-2])(([0-2][1-9])|10|20|30|31)\d{3}(\d|X|x)$/,
                            inputErrorMessage: '身份证号格式不正确'
                        }).then(({ value, action }) => {
                            if (action === 'confirm') {
                                console.log("Value" + value);
                                var dangerPostData = {
                                    'userId': this.$store.state.userdata.userId,
                                    'userName': this.$store.state.userdata.userName,
                                    'userEnterId': value,
                                    postData: this.addformData
                                }
                                this.$axios({
                                    method: 'post',
                                    url: "http://localhost:8080/professors/danger_add",
                                    data: JSON.stringify(dangerPostData),
                                    headers: { 'Content-Type': 'application/json' },

                                }).then(res => {
                                    if (res.data.code == 1) {

                                        this.$message({
                                            type: 'success',
                                            message: value + "添加Id为" + this.addformData.proId + "的professor，危险操作已被记录"
                                        });
                                        this.fetchData();
                                    } else {
                                        if (res.data.msg == "ADD_FAILE") {
                                            this.$message({
                                                type: 'error',
                                                message: "添加失败！但结果已记录！"
                                            });
                                        }
                                        if (res.data.msg == "ID_duplicate") {
                                            this.$message({
                                                type: 'error',
                                                message: "Id为" + this.addformData.proId + "的专家已经存在！"
                                            });
                                        }
                                        if (res.data.msg == "ENTERID_NAT_MATCH") {
                                            this.$message({
                                                type: 'error',
                                                message: "身份信息与本人信息不服请勿盗用！"
                                            });
                                        }

                                    }
                                })


                            }
                        }).catch(() => {
                            this.$message({
                                type: 'info',
                                message: '取消输入'
                            });
                        });
                        this.dialogAddFormVisible = false;
                    }
                })
                
            },
            async fetchData(){
                console.log(this.selectFormData);
                this.$axios({
                    method: 'post',
                    url: 'http://localhost:8080/professors',
                    data: this.selectFormData,
                    headers: {
                        'Content-Type': 'multipart/form-data'
                    }
                }).then(res => {
                    this.totalCount = res.data.data.total;
                    this.tableData = res.data.data.rows;
                    console.log(this.tableData);
                })
                this.$axios({
                    method: 'get',
                    url: 'http://localhost:8080/class',
                }).then(res => {
                    if(res.data.code==1){
                        this.classes = res.data.data;
                        
                    }
                    
                })
                this.$axios({
                    method: 'get',
                    url: 'http://localhost:8080/auth/all'
                    
                }).then(res => {
                    this.auths = res.data.data;
                })
                
            },
            handleSizeChange(size) {
                this.selectFormData.pageSize = size;
                this.fetchData();
            },
            handleCurrentChange(page) {
                this.selectFormData.currentPage = page;
                this.fetchData();
            },
            handleLowAgeChange() {
                if (this.selectFormData.proLowAge !== '') {
                    this.filteredMaxAges = this.allAges.filter(age => age > this.selectFormData.proLowAge);
                } else {
                    this.filteredMaxAges = [...this.allAges]; // 当清除最小年龄时恢复所有最大年龄选项
                }
            },
            //查找
            findByData() {
                this.fetchData();
            },
            resetForm() {
                this.$refs.selectFormData.resetFields();
                this.fetchData();
            },
             getName(iden) {
                let val = iden.length;
                let sex = null;
                let myDate = new Date();
                let month = myDate.getMonth() + 1;
                let day = myDate.getDate();
                let age = 0;
                let birth = null;
                let password=null;
                if (val === 18) {
                    age = myDate.getFullYear() - iden.substring(6, 10) - 1;
                    sex = iden.substring(16, 17);
                    birth = iden.substring(6, 10) + "-" + iden.substring(10, 12) + "-" + iden.substring(12, 14);
                    if (iden.substring(10, 12) < month || iden.substring(10, 12) == month && iden.substring(12, 14) <= day) age++;
                    password=iden.substring(12,18);
                }
                if (val === 15) {
                    age = myDate.getFullYear() - iden.substring(6, 8) - 1901;
                    sex = iden.substring(13, 14);
                    password = iden.substring(9, 15);
                    birth = "19" + iden.substring(6, 8) + "-" + iden.substring(8, 10) + "-" + iden.substring(10, 12);
                    if (iden.substring(8, 10) < month || iden.substring(8, 10) == month && iden.substring(10, 12) <= day) age++;
                }

                if (sex % 2 === 0)
                    sex = 0
                else
                    sex = 1
                this.addformData.proGender = sex;
                this.addformData.proAge =age ;
                this.addformData.proBirth=birth;
                this.addformData.proPassword=password;
                
            },
            editRow(index, row) {
                this.$confirm("此编辑操作为危险操作，如果提交会被记录操作，是否继续？",'提示',{
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(action => {
                    if(action==='confirm'){
                        this.editformData = Object.assign({}, row);
                        this.rowData = Object.assign({}, row);
                        console.log(this.editformData);
                        this.dialogEditFormVisible = true;
                    }    
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消编辑'
                    });
                });     
                
            },
            resetPassword(){
                this.password_reset=true;
                if(this.editformData.proId.length==18){
                    this.editformData.proPassword = this.editformData.proId.substring(12, 18);
                }
                if (this.editformData.proId.length == 15) {
                    this.editformData.proPassword = this.editformData.proId.substring(9, 15);
                }
                
            },
            deleteRow(index, proIndex) {
                this.$prompt('此操作将被记录，请输入身份证号', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    inputPattern: /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[0-2])(([0-2][1-9])|10|20|30|31)\d{3}(\d|X|x)$/,
                    inputErrorMessage: '身份证号格式不正确'
                }).then(({ value,action }) => {
                    if(action==='confirm'){
                        console.log("Value" + value);
                        var deleteUser = {
                            UserId: this.$store.state.userdata.userId,
                            UserName: this.$store.state.userdata.userName,
                            UserEnterId: value,
                            deleteproIndex: proIndex
                        }
                        
                        this.$axios({
                            method: 'post',
                            url: "http://localhost:8080/professors/danger_delete",
                            data: deleteUser,
                            headers: {
                                'Content-Type': 'multipart/form-data'
                            }
                        }).then(res => {
                            if (res.data.code == 1) {
                                
                                this.$message({
                                    type: 'success',
                                    message: value + "删除了第"+proIndex+"号professor，危险操作已被记录"
                                });
                                this.fetchData();
                            } else {
                                if(res.data.msg=="DELETE_FAILE"){
                                    this.$message({
                                        type: 'error',
                                        message: "删除失败！但结果已记录！"
                                    });
                                }
                                if (res.data.msg == "ENTERID_NAT_MATCH") {
                                    this.$message({
                                        type: 'error',
                                        message: "身份信息与本人信息不服请勿盗用！"
                                    });
                                }
                                
                            }
                        })
                    }
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '取消输入'
                    });
                });
                
            },
            

        },
        created() {
            window.addEventListener('resize', this.getHeight)
        },
        mounted() {
            this.fetchData();
            window.addEventListener('resize', this.getHeight)
        },
    }
</script>

<style lang="less" scoped>
.selectForm{
    .el-form-item__label{
        padding-right: 0px;
    }
    .el-form-item__content{
        margin-left: 0px;
        .el-input{
            width: 70%;
            margin-left: 0px;
        }
    }
}
#EditDialog{
    .el-input{
        width: 50%;
    }
}
</style>